//
//  TopicDeleteViewController.swift
//  Venus
//
//  Created by Smith_Yang on 2018/8/6.
//  Copyright © 2018 zhaowang. All rights reserved.
//

import UIKit

class TopicDeleteViewController: BaseViewController {
    
    @IBOutlet weak var deleteReasonTextview: HintTextView!
    
    @IBOutlet weak var submitButton: UIButton!
    
    var topicModel : TopicModel = TopicModel();
    
    typealias endBlock = (_ success: Bool) -> ()
    var deletedBlock: endBlock?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    @IBAction func submitAction(_ sender: Any) {
        
        if (deleteReasonTextview.text.isEmpty){
            
            return
        }
        
        guard let remark = deleteReasonTextview.text else {return}
        
        let dict:Dictionary = [
            "userId":String(UserInfo.shareInstance.userModel().id),
            "topicId": topicModel.id,
            "remark":remark
            ] as [String : Any]
        
        let current = String().currentTime()
        let api = kHost + kdeleteTopicList + "".apiF(time: current, sign: "")  + "&topicId=\(topicModel.id)"
        self.hudLoad()
        TempNetTool.post(api, parameters: dict, progress: nil, success: { [weak self] (result) in
            self?.hudHide()
            if let block = self?.deletedBlock {
                block(true)
            }
            self?.navigationController?.popViewController(animated: true)
        }) {  [weak self](error) in
            self?.hudHide()
            self?.hudLoadMessage("error")
        }
    }

}

extension TopicDeleteViewController {
    
    func setupUI() {
        title = "删除话题"
        deleteReasonTextview.hint = "请输入删除原因..."
        
        submitButton.layer.cornerRadius = 20
        submitButton.clipsToBounds = true
        submitButton.backgroundColor = UIColor.init(hex: "#17bbfe")!

    }
    
}
